package com.ruoyi.web.controller.member.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.entity.VO.member.MemberVipTypeSearchVO;
import com.ruoyi.common.entity.VO.member.MemberVipTypeVO;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.web.controller.member.service.IBackMemberVipTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 会员等级管理
 */
@Controller
@RequestMapping("/back/memberVipType")
public class BackMemberVipTypeController extends BaseController {
    private String prefix = "member/vipType";

    @Resource
    private IBackMemberVipTypeService vipTypeService;

    /**
     * 会员等级列表-页面跳转
     *
     * @return
     */
    @RequiresPermissions("back:memberVipType:list")
    @GetMapping()
    public String list(ModelMap mmap) {
        return prefix + "/list";
    }


    /**
     * 查询会员等级列表-数据
     */
    @RequiresPermissions("back:memberVipType:list")
    @PostMapping("/searchList")
    @ResponseBody
    public TableDataInfo searchList(MemberVipTypeSearchVO searchVO) {
        startPage();
        List<MemberVipTypeVO> list = vipTypeService.searchList(searchVO);
        return getDataTable(list);
    }
    

    /**
     * 编辑会员等级-数据
     */
    @Log(title = "总后台-会员VIP等级管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("back:memberVipType:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(MemberVipTypeVO MemberVipTypeVO) {
        try {
            MemberVipTypeVO.setUpdateBy(ShiroUtils.getSysUser().getUserName());
            MemberVipTypeVO.setUpdateTime(new Date());
            vipTypeService.edit(MemberVipTypeVO);
            return success();
        } catch (BusinessException e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除会员等级
     */
//    @Log(title = "总后台-会员等级管理", businessType = BusinessType.DELETE)
//    @RequiresPermissions("back:memberVipType:remove")
//    @PostMapping("/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids) {
//        return toAjax(vipTypeService.removeMemberByIds(ids));
//    }

}
